package com.wx.spider.sql.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wx.spider.common.model.CommonResponse;
import com.wx.spider.common.pojo.db.WxBiz;
import com.wx.spider.sql.service.WxBizService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author:feng
 * @create:2021-04-25 12:46
 */
@RestController
@RequestMapping("/wxbiz")
public class WxBizController {
    @Autowired
    private WxBizService wxBizService;

    @GetMapping("/findAll")
    private CommonResponse<List<WxBiz>> findAll(){
        try{
            QueryWrapper<WxBiz> wrapper = new QueryWrapper<>();
            wrapper.eq("delflag", 0).orderByDesc("orderindex").orderByAsc("addtime");
            List<WxBiz> list = wxBizService.list(wrapper);
            return CommonResponse.succeed(list);
        }catch (Exception e) {
            e.printStackTrace();
            return CommonResponse.INTERNAL_ERROR_RESPONSE;
        }
    }

    @RequestMapping("/findByBiz")
    private CommonResponse<WxBiz> findByBiz(@RequestBody String biz){
        try{
            QueryWrapper<WxBiz> wrapper = new QueryWrapper<>();
            wrapper.eq("delflag", 0).eq("biz", biz);
            WxBiz wxBiz = wxBizService.getOne(wrapper);
            return CommonResponse.succeed(wxBiz);
        }catch (Exception e) {
            e.printStackTrace();
            return CommonResponse.INTERNAL_ERROR_RESPONSE;
        }
    }
}
